package com.dfrz.problem.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dfrz.problem.dao.EmployeeDao;
import com.dfrz.problem.dao.ProjectDao;
import com.dfrz.problem.dao.RoleDao;
import com.dfrz.problem.dao.impl.EmployeeDaoImpl;
import com.dfrz.problem.model.Employee;
import com.dfrz.problem.model.ProjectInfo;
import com.dfrz.problem.model.Role;
import com.dfrz.problem.service.RegisterService;
import com.dfrz.problem.utils.IConstant;
import com.dfrz.problem.utils.Result;

public class RegisterServiceImpl implements RegisterService {

	private static final Logger logger = LoggerFactory.getLogger(EmployeeDaoImpl.class);
	private EmployeeDao employeeDao;
	private RoleDao roleDao;
	private ProjectDao projectDao;
	
	@Override
	public Result<Employee> addEmployee(Employee employee) {
		employee.setRole(new Role(1, "未分配", "系统默认角色",new Date()));
		employee.setProject(new ProjectInfo(1, 0, 1, "未分配项目", "未分配项目", new Date(), 30));
		boolean addSuccess = employeeDao.addEmployee(employee);
		Result<Employee> result = new Result<Employee>();
		
		if(addSuccess){
			logger.debug("账户 {} 注册成功!",employee.getEmployeeEmail());
			result.setCode(IConstant.REGISTER_SUCCESS);
		}else{
			logger.debug("账户 {} 注册失败",employee.getEmployeeEmail());
			result.setCode(IConstant.EXISTION_ACCOUNT);
		}
		result.setResult(employee);
		
		return result;
	}

	@Override
	public void create() {
		roleDao.createRole();
		projectDao.createProject();
	}

	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}
	
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}
	
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}
}
